//
//  ZH_EvaluationInforTableViewCell.m
//  ChangeMerchants
//
//  Created by zhangliwen on 2018/10/10.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_EvaluationInforTableViewCell.h"
@interface ZH_EvaluationInforTableViewCell()
@property (nonatomic,weak)UIImageView *photoImage;
@property (nonatomic,weak)UILabel *titleLabel;
//score
@property (nonatomic,weak)UILabel *scoreLabel;
//content
@property (nonatomic,weak)UILabel *contentLabel;
@end
@implementation ZH_EvaluationInforTableViewCell

///创建
+ (instancetype)cellWithTableView:(UITableView*)tableView
{
    static NSString *ID = @"ZH_EvaluationInforTableViewCell";
    ZH_EvaluationInforTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell == nil){
        cell = [[ZH_EvaluationInforTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}

///初始化
-(void)initDefault
{
    [self unShowClickEffect];
    self.topShortLineImage.hidden = NO;
}
- (void)loadSubviewConstraints{
    [self.photoImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(14));
        make.left.equalTo(self.contentView).offset(FITSCALE(22));
        make.width.mas_equalTo(FITSCALE(38));
        make.height.mas_equalTo(FITSCALE(38));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.photoImage);
        make.left.equalTo(self.photoImage.mas_right).offset(FITSCALE(6));
    }];
    NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:0];
    [array addObjectsFromArray:@[@"icon_star_selected",@"icon_star_selected",@"icon_star_selected",@"icon_halfstar",@"icon_star1"]];
    for (NSInteger i = 0; i < array.count; i ++) {
        UIImageView *image = [UIImageView createImageViewWithName:array[i]];
        [self addSubview:image];
        [image mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.titleLabel);
            make.left.equalTo(self.titleLabel.mas_right).offset(FITSCALE(10 + i * 17));
        }];
    }
    [self.scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel);
        make.left.equalTo(self.contentView).offset(FITSCALE(220));
    }];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(FITSCALE(14));
        make.left.equalTo(self.titleLabel);
        make.right.equalTo(self.contentView).offset(FITSCALE(-22));
        make.bottom.equalTo(self.contentView).offset(FITSCALE(-10));
    }];
}
- (void)updateUI:(NSDictionary *)data{
    if (data) {
        [self.photoImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVER_TEST,data[@"head"]]]];
        self.titleLabel.text = [NSString stringWithFormat:@"%@",data[@"nickname"]];
        self.scoreLabel.text = [NSString stringWithFormat:@"%@分",data[@"matching_points"]];
        self.contentLabel.text = [NSString stringWithFormat:@"%@",data[@"replay_content"]];
    }
}
#pragma mark - getter,setter
- (UIImageView *)photoImage{
    if (!_photoImage) {
        UIImageView *image = [UIImageView createImageViewWithName:@""];
        image.backgroundColor = [UIColor redColor];
        image.layer.cornerRadius = FITSCALE(19);
        image.layer.masksToBounds = YES;
        image.clipsToBounds = YES;
        [self.contentView addSubview:_photoImage = image];
    }
    return _photoImage;
}
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        UILabel *label = [UILabel createLabelWithText:@"TT" font:kFontSize_24];
        [self.contentView addSubview:_titleLabel = label];
    }
    return _titleLabel;
}
- (UILabel *)scoreLabel{
    if (!_scoreLabel) {
        UILabel *label = [UILabel createLabelWithText:@"4.5分" font:kFontSize_24];
        label.textColor = [UIColor colorWithHexString:@"#F0302F"];
        [self.contentView addSubview:_scoreLabel = label];
    }
    return _scoreLabel;
}

- (UILabel *)contentLabel{
    if (!_contentLabel) {
        UILabel *label = [UILabel createLabelWithText:@"评论内容, 评论内容,评论内容,评论内容..." font:kFontSize_26];
        [label lableAutoLinefeed];
        [self.contentView addSubview:_contentLabel = label];
    }
    return _contentLabel;
}
@end
